{
	template:`
	<a-page-header title="机构设置">
		<a-row :gutter="8">
			<a-col v-if="isLoad" :span="8">
			<a-input-search v-model:value="searchText" placeholder="请输入部门编号或部门名称" :allowClear="true"/>
				<div style="max-height:500px;overflow-y:auto;overflow-x:hidden;margin:10px 0;padding-right:8px;">
					<template v-for="item in list">
						<a-row type="flex" style="padding-top:10px;">
							<a-col flex="auto">
								<a-popconfirm :title="'确定要'+(item.status=='0'?'停用':'启用')+'吗?'" @confirm="setStatus(item)">
									<a-tag :color="item.status=='0'?'processing':'error'">{{item.status=='0'?'正常':'停用'}}</a-tag>
								</a-popconfirm>
								<a-typography-text v-if="selectOid==item.oid" strong>{{item.name}}</a-typography-text>
								<a-typography-text v-else-if="item.business=='B'" type="danger" @click="showOrgUser(item.oid)" style="cursor:pointer;">{{item.name}}</a-typography-text>
								<a-typography-link v-else @click="showOrgUser(item.oid)">{{item.name}}</a-typography-link>
							</a-col>
							<a-col>
								<a-space>
									<a-button type="text" size="small" @click="modGroup(item.oid);"><m-icon name="icon-icon-6"></m-icon>修改</a-button>
									<a-button type="text" size="small" @click="addGroup(item.oid);"><m-icon name="icon-icon-54"></m-icon>添加</a-button>
								</a-space>
							</a-col>
						</a-row>
						<template v-for="dept in map[item.oid].children">
                            <a-row v-if="isSearch(dept.num,dept.name)" type="flex" style="padding-top:10px;">
                                <a-col flex="auto">
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                    <a-popconfirm :title="'确定要'+(dept.status=='0'?'停用':'启用')+'吗?'" @confirm="setStatus(dept)">
                                        <a-tag :color="dept.status=='0'?'processing':'error'">{{dept.status=='0'?'正常':'停用'}}</a-tag>
                                    </a-popconfirm>
                                    <a-typography-text v-if="selectOid==dept.oid" strong>{{dept.name}}</a-typography-text>
                                    <a-typography-text v-else-if="dept.business=='B'" type="danger" @click="showOrgUser(dept.oid)" style="cursor:pointer;">{{dept.name}}</a-typography-text>
                                    <a-typography-link v-else @click="showOrgUser(dept.oid)">{{dept.name}}</a-typography-link>
                                </a-col>
                                <a-col>
                                    <a-space>
                                        <a-button type="text" size="small" @click="modGroup(dept.oid);"><m-icon name="icon-icon-6"></m-icon>修改</a-button>
                                        <a-button type="text" size="small" @click="addGroup(dept.oid);"><m-icon name="icon-icon-54"></m-icon>添加</a-button>
                                    </a-space>
                                </a-col>
                            </a-row>
                            <template v-for="group in map[dept.oid].children">
                                <a-row type="flex">
                                    <a-col flex="60px">
                                        &nbsp;
                                    </a-col>
                                    <a-col flex="auto">
                                        <span v-if="isSearch(group.num,group.name)">
                                            <a-tag style="margin:7px 7px 0 0;">
                                                <span style="padding: 0 7px 0 0;">
                                                    <a-typography-text v-if="selectOid==group.oid" strong>{{group.name}}</a-typography-text>
                                                    <a-typography-text v-else-if="group.business=='B'" type="danger" @click="showOrgUser(group.oid)" style="cursor:pointer;">{{group.name}}</a-typography-text>
                                                    <a-typography-link v-else @click="showOrgUser(group.oid)">{{group.name}}</a-typography-link>
                                                </span>
                                                <a-typography-link @click="modGroup(group.oid)">修改</a-typography-link>
                                            </a-tag>
                                        </span>
                                    </a-col>
                                </a-row>
                            </template>
						</template>
						<a-divider style="margin:12px 0;" />
					</template>
				</div>
				<a-row :gutter="10">
					<a-col :span="12">
						<a-button type="primary" @click="addGroup('');" block>添加机构</a-button>
					</a-col>
					<a-col :span="12">
						<a-button @click="showOrgUser('')" block>全部用户</a-button>
					</a-col>
				</a-row>
			</a-col>
			<a-col :span="isLoad?16:24">
				<a-card :hoverable="true" :bodyStyle="{padding:0}" style="margin-top:-40px;">
					<div :id="'orgUserList'+key"></div>
				</a-card>
			</a-col>
		</a-row>
	</a-page-header>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
			listV3:null,
			selectOid:'',
			searchText:'',
			isLoad:false,
			list:[],
			map:{}
		};
	},
	mounted(){
		this.initGroup();
		this.showOrgUser('');
	},
	methods:{
		initGroup:function(){
			this.requestData("action/manage/adminGroup/getList",
				{"model":{"type":"C"}},
				function(json){
					if(json.code==0){
						this.map={};
						for(let i=0;i<json.list.length;i++){
							this.map[json.list[i].oid]=json.list[i];
						}
						this.list=[];
						for(let k in this.map){
							let group=this.map[k];
							group['title']=group.name+' - '+group.num;
							if(group.parent&&group.parent.oid){
								let parent=this.map[group.parent.oid];
								if(!parent.children) parent.children=[];
								parent.children.push(group);
							}else{
								this.list.push(group);
							}
						}
						this.isLoad=true;
					}else{
						this.$message.error(json.msg);
					}
				}.bind(this)
			);
		},
		isSearch:function(num,name){
		    if(this.searchText){
		        if(num.indexOf(this.searchText)>=0||name.indexOf(this.searchText)>=0)
		            return true;
		        else
		            return false;
		    }
		    return true;
		},
		setStatus:function(item){
			var method=item.status=='0'?'doDisable':'doRecovery';
			this.requestData("action/manage/adminGroup/"+method,
				{"model":{"oid":item.oid}},
				function(json){
					this.$message[json.code==0?'success':'error'](json.msg);
					if(json.code==0){
						item.status=item.status=='0'?'9':'0';
					}
				}.bind(this)
			);
		},
		addGroup:function(parentOid){
			this.openPage("action/manage/adminGroup/toEdit",
				{model:{parent:{oid:parentOid},type:'C'}},
				function(flag,obj){
					if(flag){
						this.initGroup();
					}
		        }.bind(this),
		        '700px'
	        );
		},
		modGroup:function(oid){
			this.openPage("action/manage/adminGroup/toEdit",
				{model:{oid:oid}},
				function(flag,obj){
					if(flag){
						this.initGroup();
					}
		        }.bind(this),
		        '700px'
	        );
		},
		showOrgUser:function(deptOid){
			this.selectOid=deptOid;
			if(this.listV3) this.listV3.unmount();
			this.loadPage("orgUserList"+this.key,
				"action/manage/adminGroupLink/orgUserList",
				{params:{"deptOid":deptOid}},
				function(pv,v3){
					this.listV3=v3;
		        }.bind(this)
	        );
		},
	}
}